﻿@using Presentation.Web.Admin
@using (Ajax.BeginForm("addmenu", "role", new AjaxOptions
{
    HttpMethod = "post",
    OnBegin = "checkedAddForm",
    OnFailure = "addFailure",
    OnSuccess = "addSuccess"
}))
{
    @Html.ValidationSummary(true)
    <fieldset class="module width_full">
        <script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
        <script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
        @Html.Partial("_MenuForm", new Domain.Dto.RoleMenuDto())
    </fieldset>
    <p>
        @{
    if (Html.HasUiPermission(this.ViewContext, "addmenu"))
    {
            <input type="submit" value="添加" class="alt_btn module_margin" />
    }
        }
    </p>
}
<script type="text/javascript">

    function checkedAddForm() {
        var res = true;
        if ($('#Name').val() == 0) {
            $('#Name').focus();
            alert("菜单名不能为空");
            res = false;
            return res;
        }
        if ($('#Url').val() == "") {
            alert("模块入口地址不能为空");
            $('#Url').focus();
            res = false;
            return res;
        }
        return res;
    }

    function addSuccess(res) {
        if (res.success) {
            alert("添加成功");
            $('#addRoleMenuWindow').data('tWindow').close();
            $("#RoleMenuGrid").data("tGrid").rebind();
        }
        else {
            alert(res.message);
        }
    }

    function addFailure() {
        alert("添加失败了T_T！");
    }
</script>
